#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/5/14 9:27
# @Author  : lj
# @File    : main.py
from typing import Optional

from fastapi import FastAPI,Depends
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware



from dependencies import get_query_token, get_token_header
from internal import admin
from routers import items, users


app = FastAPI(dependencies=[Depends(get_query_token)])


origins = [
    "http://localhost",
    "http://localhost:8080",
]

app.add_middleware(
    CORSMiddleware,
    #允许跨域请求的源列表
    allow_origins=origins,
    allow_credentials=True,
    #允许跨域请求的 HTTP 方法列表。默认为 ['GET']。你可以使用 ['*'] 来允许所有标准方法
    allow_methods=["*"],
    #允许跨域请求的 HTTP 请求头列表。默认为 []。你可以使用 ['*'] 允许所有的请求头。Accept、Accept-Language、Content-Language 以及 Content-Type 请求头总是允许 CORS 请求
    allow_headers=["*"],
)

app.include_router(users.router)
app.include_router(items.router)
app.include_router(
    admin.router,
    prefix="/admin",
    tags=["admin"],
    dependencies=[Depends(get_token_header)],
    responses={418: {"description": "I'm a teapot"}},
)

@app.get("/")
async def root():
    return {"message": "Hello Bigger Applications!"}